// pages/group/group.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    istrue:false,
    ismodifytrue:false,
    account:null,
    prolist:[],
    editnum:'',
    editid:null,
  },
  bindKeyInput(e){
    let that = this;
    let account = e.detail.value;
    console.log(account)
    that.setData({
      account
    })
  },
  modify(e){
    let that = this;
    let prolist = that.data.prolist
    let index = e.currentTarget.dataset.index
    console.log(e.currentTarget.dataset.index)
    // let that = this;
    that.setData({
      ismodifytrue:true
    })
    that.setData({
      editnum:prolist[index].group,
      editid:prolist[index].id,
    })

  },
  //保存
  onave(e){
    let that = this; 
    let account = that.data.account
    var prolist = wx.getStorageSync('prolist')
    if(account==null){
      wx.showToast({ title: '分组名称不能为空', icon: 'none', duration: 1500 })
    }else{
      wx.request({
        url: 'https://wxtp.hephp.cn/Api/Group/add', //仅为示例，并非真实的接口地址
        data: {
          uid:prolist.data.uid,
          group:account,
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          let prolist = res.data;
          if(prolist.code==200){
            that.getlist()
            that.setData({
              istrue:false
            })
            wx.showToast({ title: prolist.msg, icon: 'success', duration: 1500 })
          }else{
            wx.showToast({ title: prolist.msg, icon: 'error', duration: 1500 })
          }
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this; 
    that.getlist()
  },
  //列表
  getlist(e){
    let that = this; 
    var prolist = wx.getStorageSync('prolist')
    wx.request({
      url: 'https://wxtp.hephp.cn/Api/Group/get', //仅为示例，并非真实的接口地址
      data: {
        uid:prolist.data.uid,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        let prolist = res.data.data;
        console.log(prolist)
        that.setData({
          prolist:prolist
        })
      }
    })
  },

  onfenzu(e){
    let that = this;
    that.setData({
      istrue:true
    })
  },
  // 返回
  onreturn(e){
    let that = this;
    that.setData({
      istrue:false
    })
  },
  //获取修改input数据
  editbindKeyInput(e){
    let that = this;
    let editnum = e.detail.value;
    that.setData({
      editnum:editnum
    })
  },


//修改返回
  onxgturn(e){
    let that = this;
    that.setData({
      ismodifytrue:false
    })
  },
  //修改分组
  onmodifyave(e){
    let that = this;
    var prolist = wx.getStorageSync('prolist')
    let editnum = that.data.editnum
    let editid = that.data.editid
    wx.request({
      url: 'https://wxtp.hephp.cn/Api/Group/edit', //仅为示例，并非真实的接口地址
      data: {
        uid:prolist.data.uid,
        id:editid,
        group:editnum
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        let prolist = res.data.data;
        //console.log(prolist)
        // that.setData({
        //   prolist:prolist
        // })
        that.getlist()
      }
    })
    that.setData({
      ismodifytrue:false
    })
  },
  //删除分组
  delete(e){
    let that = this;
    var prolist = wx.getStorageSync('prolist')
    let editid = e.currentTarget.dataset.index
    wx.request({
      url: 'https://wxtp.hephp.cn/Api/Group/del', //仅为示例，并非真实的接口地址
      data: {
        uid:prolist.data.uid,
        id:editid,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        let prolist = res.data.data;
        that.getlist()
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})